<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>表单输入绑定</h2>
      <!-- 受控组件 -->
      <!-- <input type="text" :value="textValue" @input="handleChange" /> -->

      <!-- v-model用于做表单输入绑定，数据的双向绑定 -->

      <input type="text" v-model="textValue" />
      <button @click="handleClick">btn</button>
      <p>textValue: {{ textValue }}</p>

      <h3>普通文本框</h3>
      <input type="text" v-model="value" />
      <p>value: {{ value }}</p>

      <h3>多行文本框</h3>
      <textarea v-model="areaValue"></textarea>
      <p>areaValue: {{ areaValue }}</p>

      <h3>复选框</h3>
      <!-- 复选框只有一个的时候，自动绑定布尔值 -->
      <input
        type="checkbox"
        id="checkbox"
        v-model="checked"
        true-value="yes"
        false-value="no"
      />
      <label for="checkbox">{{ checked }}</label>

      <!-- 如果有多个复选框同时绑定了同一个变量，自动绑定数组类型 -->
      <input type="checkbox" v-model="likes" value="sing" />唱歌
      <input type="checkbox" v-model="likes" value="dance" />跳舞
      <input type="checkbox" v-model="likes" value="sleep" />睡觉
      <p>likes: {{ likes }}</p>

      <h3>单选框</h3>
      <div>Picked: {{ picked }}</div>
      <input type="radio" id="one" value="One" v-model="picked" />
      <label for="one">One</label>
      <input type="radio" id="two" value="Two" v-model="picked" />
      <label for="two">Two</label>

      <h3>下拉菜单</h3>
      <div>Selected: {{ selected }}</div>
      <select v-model="selected">
        <option disabled value="">Please select one</option>
        <option value="1">A</option>
        <option value="2">B</option>
        <option value="3">C</option>
      </select>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            textValue: "abc",
            value: "",
            areaValue: "",
            checked: true,
            likes: [],
            picked: "",
            selected: "",
          };
        },
        methods: {
          handleClick() {
            console.log(this.textValue);
          },
          handleChange(e) {
            this.textValue = e.target.value;
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
